package com.icim.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.Connection;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.icim.common.LoadHistoryConfig;
import com.icim.rabbitmq.util.RabbitmqManager;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.AMQP.Queue.DeclareOk;

/**   
* @Title: RabbitMQUtil.java
* @Package com.icim.rabbitmq
* @Description: TODO(添加描述)
* @author Lynn.Sea
* @date 2014-7-31 下午6:25:30    
* @version V1.0   
*/
@Component
public class RabbitMQUtil {
	@Autowired
	AmqpTemplate amqpTemplate;

	@Resource
	RabbitAdmin rabbitAdmin;

	@Resource
	Queue historyQueue;
	@Resource
	CachingConnectionFactory rabbitConnFactory;

	@Autowired
	LoadHistoryConfig loadHistoryConfig;
	@Autowired
	RabbitmqManager rabbitmqManager;
	public int getQueueDeepth(String queueName){
		int deepth = 0;
		try {
			Connection conn = rabbitConnFactory.createConnection();
			Channel channel = conn.createChannel(false);
			DeclareOk dOk = channel.queueDeclarePassive(queueName);
			deepth = dOk.getMessageCount();
			System.out.println(queueName+"'deepth:" + deepth);
		    conn.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return deepth;
	}
}
